<template>
	<view>
		<!-- 状态栏 -->
		<view class="statusBar" :style="'height:'+statusBarHeight+'px'"></view>
		<view class="myheader padding-sm  flex justify-between">
			<view class="font-sub-title">
				<text class="cuIcon-back margin-right-ssm" @click="back()"></text>
				勿扰设置
			</view>
			<text class="font-sub-title" @click="save">保存</text>
		</view>
		<view class="cu-list menu">
			<view class="cu-item">
				<view class="content">
					<text>勿扰设置</text>
				</view>
				<view class="action text-gray">
					<switch class="blue" @change="open" :class="isopen?'checked':''" :checked="isopen"></switch>
				</view>
			</view>
			<view class="cu-item arrow">
				<view class="content">
					<text>开始时间</text>
				</view>
				<view class="action text-gray">
					<picker mode="time" :value="startTime" @change="bindstartTimeChange">
						<view>{{startTime}}</view>
					</picker>
				</view>
			</view>
			<view class="cu-item arrow">
				<view class="content">
					<text>结束时间</text>
				</view>
				<view class="action text-gray">
					<picker mode="time" :value="endTime" @change="bindendTimeChange">
						<view>{{endTime}}</view>
					</picker>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const bandSDK = uni.requireNativePlugin('BandSDK')
	var that;
	export default {
		data() {
			return {
				statusBarHeight: Vue.prototype.StatusBar,
				startTime:uni.getStorageSync("nodisturbStartTime")||'22:00',
				endTime:uni.getStorageSync("nodisturbEndTime")||'07:00',
				isopen:uni.getStorageSync("nodisturbOpen")||false
			}
		},
		onLoad() {
			that = this;
		},
		methods: {
			back(){
				uni.navigateBack();
			},
			open(e){
				this.isopen = e.target.value
			},
			bindstartTimeChange(e){
				this.startTime = e.target.value
			},
			bindendTimeChange(e){
				this.endTime = e.target.value
			},
			save(){
				bandSDK.settingNotDisturb({
					on:that.isopen?'1':'0',
					startTimeHour:that.startTime.substring(0,2),
					startTimeMin:that.startTime.substring(3,5),
					endTimeHour:that.endTime.substring(0,2),
					endTimeMin:that.endTime.substring(3,5)
				},res=>{
					if(res=='success'){
						uni.setStorageSync("nodisturbStartTime",that.startTime)
						uni.setStorageSync("nodisturbEndTime",that.endTime)
						uni.setStorageSync("nodisturbOpen",that.isopen)
						uni.showToast({
							title:"保存成功"
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
